package day2;

import java.io.*;

//测试复制(先对文件进行读取 再对文件进行写入)
public class TestCopy {
    public static void main(String[] args) {
        File in = new File("d://IO//video//a.mp4");
        File out = new File("d://IO//video//movie//new.mp4");
        if (in.exists()){
            File parentOut = out.getParentFile();
            if (!parentOut.exists()) parentOut.mkdirs();
            //统计当前系统时间 毫秒数
            long start = System.currentTimeMillis();
            FileInputStream fis = null;
            FileOutputStream fos = null;
            try {
                fis = new FileInputStream(in);
                fos = new FileOutputStream(out);
                byte[] bs = new byte[1024];
                int len = 0;
                while ((len = fis.read(bs)) != -1){
                    fos.write(bs,0,len);
                }
                //统计结束时的系统时间
                long end = System.currentTimeMillis();
                System.out.println("复制成功后："+(end-start)+"ms");
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if (fis!=null) fis.close();
                    if (fos!=null) fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }else {
            System.out.println("要复制的文件不存在");
        }
    }
}
